//package com.smile.handler;
//
//import com.alibaba.fastjson2.JSONObject;
//
//import com.smile.mqtt.handler.AbstractAirportBindStatusHandler;
//
//import org.eclipse.paho.client.mqttv3.MqttClient;
//import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
//import org.eclipse.paho.client.mqttv3.MqttException;
//import org.eclipse.paho.client.mqttv3.MqttMessage;
//import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Component
//public class DefaultAirportBindStatusHandler extends AbstractAirportBindStatusHandler {
////    @Autowired
////    private DroneMapper droneMapper;
////
////    @Autowired
////    private OrganizationApi organizationApi;
////
////    @Autowired
////    private UserApi userApi;
//
//    @Override
//    public Boolean process(String data, String bid, String tid) throws MqttException {
//////        System.out.println("DefaultAirportBindStatusHandler 收到的json为:" + data);
////        JSONObject jsonObject = JSONObject.parseObject(data);
////        AirportBindStatusData airportBindStatusData = jsonObject.toJavaObject(AirportBindStatusData.class);
//////        System.out.println("反序列化后的结果为:" + airportBindStatusData);
////
////
////        //TODO 这里还没有写完
////        AirportBindStatusDetailedData airportBindStatusDetailedData = new AirportBindStatusDetailedData();
////
//////                    List<AirportBindStatusDetailedData.DeviceBindStatus> bindStatusList
//////                            = new ArrayList<>();
//////        AirportBindStatusDetailedData.DeviceBindStatus deviceBindStatus = new AirportBindStatusDetailedData.DeviceBindStatus();
////
////
////        AirportBindStatusDetailedData.BindStatusOutput bindStatusOutput = new AirportBindStatusDetailedData.BindStatusOutput();
//////        List<AirportBindStatusDetailedData.DeviceBindStatus> collect = devices.stream().map(i -> {
//////                    AirportBindStatusDetailedData.DeviceBindStatus deviceBindStatus = new AirportBindStatusDetailedData.DeviceBindStatus();
//////                    String sn = i.getSerialNumber();
//////                    QueryWrapper<FeisuanDrone> queryWrapper = new QueryWrapper<>();
//////                    queryWrapper.eq("drone_sn", sn);
//////                    List<FeisuanDrone> feisuanDrones = droneMapper.selectList(queryWrapper);
//////                    if (CollectionUtil.isEmpty(feisuanDrones)) {
//////                        throw new RuntimeException("请先添加无人机信息到后台");
//////                    } else {
//////                        deviceBindStatus.setDeviceBoundToOrganization(true);
//////                        deviceBindStatus.setDeviceCallsign(feisuanDrones.get(0).getDroneName());
//////                        deviceBindStatus.setSerialNumber(i.getSerialNumber());
//////                        GetUserByIdRequest getUserByIdRequest = new GetUserByIdRequest();
//////                        getUserByIdRequest.setId(Long.valueOf(StpUtil.getLoginId().toString()));
//////                        R<GetUserByIdResponse> userById =
//////                                userApi.getUserById(getUserByIdRequest);
//////                        if (ObjectUtil.isNull(userById) || ObjectUtil.isNull(userById.getData())) {
//////                            throw new RuntimeException("用户信息不存在");
//////                        }
//////                        Long organizationId = userById.getData().getOrganizationId();
//////                        GetOrganizationByIdRequest getOrganizationByIdRequest = new GetOrganizationByIdRequest();
//////                        getOrganizationByIdRequest.setId(organizationId);
//////                        R<GetOrganizationByIdResponse> organizationById = organizationApi.getOrganizationById(getOrganizationByIdRequest);
//////                        if (ObjectUtil.isNull(organizationById) || ObjectUtil.isNull(organizationById.getData())) {
//////                            throw new RuntimeException("组织不存在");
//////                        } else {
//////                            deviceBindStatus.setOrganizationId(organizationId.toString());
//////                            deviceBindStatus.setOrganizationName(organizationById.getData().getOrganizationName());
//////
//////                        }
//////
//////                    }
//////                    return deviceBindStatus;
//////
//////                }
//////        ).collect(Collectors.toList());
////
////        List<AirportBindStatusDetailedData.DeviceBindStatus> devices =
////                new ArrayList<>();
////
////        AirportBindStatusDetailedData.DeviceBindStatus deviceBindStatus = new AirportBindStatusDetailedData.DeviceBindStatus();
////        deviceBindStatus.setSerialNumber("1581F8HGX252500A0022");
////        deviceBindStatus.setOrganizationId("9veeb2");
////        deviceBindStatus.setDeviceBoundToOrganization(Boolean.TRUE);
////        deviceBindStatus.setOrganizationName("无人机1号");
////        deviceBindStatus.setDeviceCallsign("测试组织");
////        devices.add(deviceBindStatus);
////
////        AirportBindStatusDetailedData.DeviceBindStatus deviceBindStatus1 = new AirportBindStatusDetailedData.DeviceBindStatus();
////        deviceBindStatus1.setSerialNumber("8UUXN2800A00HX");
////        deviceBindStatus1.setOrganizationId("9veeb2");
////        deviceBindStatus1.setDeviceBoundToOrganization(Boolean.TRUE);
////        deviceBindStatus1.setOrganizationName("测试机场");
////        deviceBindStatus1.setDeviceCallsign("测试组织");
////        devices.add(deviceBindStatus1);
////
////        bindStatusOutput.setBindStatusList(devices);
////        airportBindStatusDetailedData.setOutput(bindStatusOutput);
////        airportBindStatusDetailedData.setResultCode(0);
////
////        DeviceConfigResponse<AirportBindStatusDetailedData> deviceConfigResponse = new DeviceConfigResponse<>();
////        deviceConfigResponse.setBid(bid);
////        deviceConfigResponse.setTid(tid);
////        deviceConfigResponse.setData(airportBindStatusDetailedData);
////        deviceConfigResponse.setTimestamp(System.currentTimeMillis());
////        deviceConfigResponse.setMethod("airport_bind_status");
////        deviceConfigResponse.setGateway("8UUXN2800A00HX");
////
////        MqttMessage message = new MqttMessage();
////        message.setQos(0);
////        message.setRetained(true);
////        message.setPayload(JSONObject.toJSONString(deviceConfigResponse).getBytes());
////        MqttClient mqttClient = new MqttClient("tcp://120.211.119.131:1883", "feisuan-mqtt-producer-client", new MemoryPersistence());
////        MqttConnectOptions connOpts = new MqttConnectOptions();
////        connOpts.setUserName("feisuan");
////        connOpts.setPassword("feisuan123456".toCharArray());
////        mqttClient.connect(connOpts);
////
////        mqttClient.publish("thing/product/" + "8UUXN2800A00HX" + "/requests_reply", message);
////        mqttCli
//
//
//        return Boolean.TRUE;
//    }
//}
